<?php
class BookMark extends AppModel {
	var $name = 'BookMark';
	var $useTable = 'book_mark_mst';
	var $belongsTo = array (
		'Job' => array (
			'className' => 'Job',
			'conditions' => "",
			'order' => '',
			'foreignKey' => 'job_id'
		)
	);
	
	function doadd($job_id,$member_id){
		$sql="insert into book_mark_mst (job_id,member_id,created,modified) values ($job_id,$member_id,to_char(now(),'YYYY-MM-DD HH24:MI:SS')::timestamp,to_char(now(),'YYYY-MM-DD HH24:MI:SS')::timestamp)";
		$this->query($sql);
	}
	function dodelete($id){
		$sql="update book_mark_mst SET deleted=to_char(now(),'YYYY-MM-DD HH24:MI:SS')::timestamp WHERE id=$id";
		$this->query($sql);
	}
	
	//list数据
	function getBookMarkList($show,$page,$member_id){
		$limit = ($page == 1 ? $show : ($show*($page-1)).','.$show);
		$sql="SELECT " .
				"BookMark.id as id0,BookMark.job_id,BookMark.member_id,BookMark.created,BookMark.modified,BookMark.deleted,Job.*, Company.company_name,Company.company_alias " .
			 "FROM book_mark_mst BookMark " .
			 "LEFT JOIN job_mst Job on Job.id = BookMark.job_id " .
			 "LEFT JOIN company_info Company on Job.company_id=Company.id " .
			 "WHERE BookMark.member_id = $member_id AND " .
			 	"BookMark.deleted is null AND " .
			 	"Job.deleted is null " .
			 "ORDER BY BookMark.created DESC LIMIT $limit";
		$data = $this->query($sql);
		
		return $data;
	}
	//分页总数
	function getBookMartCount($member_id){
		$sql = "select count(*) from job_mst Job " .
				"where Job.deleted is null and Job.id in (select job_id from book_mark_mst where deleted is null and member_id = $member_id)";
		$data = $this->query($sql);
		return $data['0']['0']['count'];
	}
}
?>